package config

import (
	"blog/asset"
	"os"

	"github.com/BurntSushi/toml"
)

type tomlConfig struct {
	Viewer Viewer
	System SystemConfig
}

type Viewer struct {
	Title       string
	Description string
	Logo        string
	Navigation  []string
	Bilibili    string
	Avatar      string
	UserName    string
	UserDesc    string
}
type SystemConfig struct {
	AppName         string
	Version         float32
	CurrentDir      string
	CdnURL          string
	QiniuAccessKey  string
	QiniuSecretKey  string
	Valine          bool
	ValineAppid     string
	ValineAppkey    string
	ValineServerURL string
}

var Cfg *tomlConfig

func init() {
	//init 程序启动的时候执行，钩子函数。每个go文件的如果有init 就会执行
	Cfg = new(tomlConfig)
	currentDir, _ := os.Getwd()
	Cfg.System.CurrentDir = currentDir
	b, _ := asset.Asset("resource/config/config.toml")
	_, err := toml.Decode(string(b), &Cfg)
	//_, err := toml.DecodeFile("config/config.toml", &Cfg)
	if err != nil {
		panic(err)
	}
}
